{% extends 'secline.html' %}
{% block title_text %}
    我的日报
{% endblock %}
{% block block_scripts %}
    <script>
        $(function () {
            loadDatatable();
            function loadDatatable() {
                $('#secline-show-lists').DataTable().destroy();
                $('#secline-show-lists').DataTable({
                    "info": false,
                    "searching": false,
                    "bFilter": false,
                    "lengthMenu": [10, 20, 25, 30, 40, 50],
                    "language": {
                        "emptyTable": "无可用数据",
                        "paginate": {
                            "next": "下一页",
                            "previous": "前一页"
                        },
                        "lengthMenu": '显示 _MENU_ 条数据'
                    },
                    "ajax": {
                        "url": GLOBAL_VARIABLE.BASE_URL + "/dutydatalist",
                        "contentType": "application/json",
                        "type": "GET",
                        "headers": {
                            "X-CSRFToken": "{{ csrf_token }}"
                        },
                        "data": function (d) {
                            d.level = 2;
                            d.currentuser = 1;
                        },
                        "dataType": "json",
                        "dataSrc": function (json) {
                            var len = json.data.length, dataobjList = [];
                            for (var i = 0; i < len; i++) {
                                var item = json.data[i];
                                dataobjList.push({
                                    "time": item.time,
                                    "dutyTitle": item.dutyTitle,
                                    "departAlias": item.departAlias,
                                    "dutyId": item.dutyId,
                                    "departId": item.departId,
                                    "departName": item.departName
                                });
                            }

                            return dataobjList;
                        }

                    },
                    "columns": [
                        {"data": "time"},
                        {"data": "dutyTitle"},
                        {"data": "departAlias"},
                        {
                            "data": "dutyId",
                            "render": function (data, type, full) {
                                var departId = full.departId, dutyId = full.dutyId, departAlias = full.departAlias,
                                    duty_time = full.time, departName = full.departName;
                                var content = '<button class="btn btn-info detail-view" data-departId="' + departId + '" data-dutyId="' + dutyId + '"  data-departAlias="' + departAlias + '" data-duty_time="' + duty_time + '">详情</button>';
                                content += '<button class= "btn btn-info edit-duty" data-departId="' + departId
                                    + '" data-dutyId="' + dutyId + '" data-departAlias="' + departAlias
                                    + '" data-duty_time="' + duty_time + '" data-departName="' + departName +
                                    '">编辑</button>';
                                return content;
                            }
                        }
                    ]
                });

                $(document).on('click', function (event) {
                    var target = event.target, departId = $(target).attr('data-departId'),
                        dutyId = $(target).attr('data-dutyId'), departAlias = $(target).attr('data-departAlias'),
                        duty_time = $(target).attr('data-duty_time');
                    var departName = $(target).attr('data-departName');
                    if ($(target).hasClass('detail-view')) {//查看日报详情
                        window.location.href = "/views?departId=" + departId + '&dutyId=' + dutyId + '&departAlias=' + departAlias + '&duty_time=' + duty_time+'&isme=1';
                    } else if ($(target).hasClass('edit-duty')) {//编辑日报
                        //判断是哪些部门，跳转到相应的创建页面（创建与编辑属于同一个页面）
                        switch (departName) {
                            case 'OP'://系统运维部
                                window.location.href = '/sysmain?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName + '&dutyId=' + dutyId;
                                break;
                            case 'SEC'://网络安全部
                                window.location.href = '/netsafe?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName + '&dutyId=' + dutyId;
                                break;
                            default:
                                window.location.href = '/common?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName + '&dutyId=' + dutyId;
                                break;
                        }
                    }
                });
            }
        });
    </script>
{% endblock %}